package com.um.jdy.platform.screen.controller;

import com.alibaba.fastjson.JSONObject;
import com.um.jdy.platform.screen.entity.vo.ScreenDataVO;
import com.um.jdy.platform.screen.manager.ScreenManager;
import com.um.springboot.starter.annotation.TokenRequired;
import com.um.springboot.starter.orm.controller.BaseController;
import com.um.springboot.starter.orm.entity.Response;
import com.um.springboot.starter.service.CacheService;
import com.um.springboot.starter.utils.JSONUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;
import java.util.concurrent.TimeUnit;

/**
 * 大屏图表管理
 *
 * @author 邓南辉
 * 日期 2023/5/11
 * 版权所有 广州优匠科技有限公司
 */
@Api(tags = "大屏图表")
@RestController
@RequestMapping("/api/v1/cms/screen")
@TokenRequired
public class ScreenController extends BaseController<ScreenManager> {

    @Autowired
    RedisTemplate redisTemplate;

    private static final String CACHE_KEY = "screenData";

    @ApiOperation("大屏数据")
    @GetMapping({"data"})
    public Response<ScreenDataVO> getScreenData(){
        ScreenDataVO data = (ScreenDataVO)redisTemplate.opsForValue().get(CACHE_KEY+"-"+manager.getComId());
        if (data == null) {
            data = manager.getScreenData();
            redisTemplate.opsForValue().set(CACHE_KEY+"-"+manager.getComId(), data, 1L, TimeUnit.MINUTES);
        }
        return Response.success(data);
    }

}